package org.cytoscape.myapp.cytoscape_app_v1.internal.tasks.groups;

import java.util.Set;
import java.util.Vector;

import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.group.CyGroup;
import org.cytoscape.group.CyGroupManager;
import org.cytoscape.model.CyNode;
import org.cytoscape.work.Task;
import org.cytoscape.work.TaskMonitor;

public class GroupsRemoveTask implements Task {
	
	private  CyApplicationManager appManager;
	private  CyGroupManager groupManager;
	
	
	public GroupsRemoveTask(CyApplicationManager appManager, CyGroupManager groupManager){
		this.appManager =  appManager;
		this.groupManager = groupManager;		
	}

	@Override
	public void run(TaskMonitor taskMonitor) throws Exception {
		taskMonitor.setTitle("Eliminando Grupos");
		taskMonitor.setStatusMessage("Iniciando");
		Set<CyGroup> groups = groupManager.getGroupSet(appManager.getCurrentNetwork());
		Vector<CyNode> padres =  new Vector<CyNode>();
		for(CyGroup group:groups){
			padres.add(group.getGroupNode());
			groupManager.destroyGroup(group);
		}
		appManager.getCurrentNetwork().removeNodes(padres);
		taskMonitor.setStatusMessage("Finalizando");
		
		
	}

	@Override
	public void cancel() {
		// TODO Auto-generated method stub
		
	}

}
